<template>
	<view style="height:100%">
		<scroll-view scroll-y style="height:100%" @scrolltolower="onPullUp()" :refresher-enabled="!is_search"
			@refresherrefresh="onRefresh" :refresher-triggered="triggered">
			<view v-if="dataList.length>0">
				<view class="team-item flex-box" v-for="(item,index) in dataList" :key="index">
					<view class="head">
						<image :src="item.headimg" class="icon-item"></image>
						<image :src="'https://static.dhlshu.cn/app/static/dealer/vip-'+item.vip_level+'.png'" class="icon-vip"
							v-if="item.vip_level>0"></image>
					</view>
					<view class="box-1">
						<view class="item-name flex-box">
							<view  v-if="!item.isEdit" class="name-set">{{item.descr?item.descr:item.nickname}}
							</view>
							<view v-else>
								<input :value="item.descr?item.descr:item.nickname" :focus="item.isEdit" auto-blur="true"
								 adjust-position="false" class=" box-1" @blur="setRemarks($event,item)" @confirm="setRemarks($event,item)"/>
							</view>
							<image v-if="!item.isEdit" :src="'https://static.dhlshu.cn/app/static/star/edit.png'" class="pic" @tap="changeStatu(item)"></image>
							<text class="item-sign" v-if="item.user_level_name">{{item.user_level_name}}</text>
						</view>
						<view class="item-mess flex-box">
							<text class="box-1">{{item.tel}}</text>
							<image src="@/static/img/tel.png" class="tel" @tap="callTel(item.tel)"></image>
						</view>
						<view class="item-time flex-box">
							<view class="box-1">{{item.create_time}}</view>
							
							<!-- <view class="box-1">
								团队业绩:({{item.group_merits}})
							</view> -->
						</view>
					</view>
				</view>
				<u-loadmore margin-top="20" :load-text="loadText" :style="loadStatus=='nomore'?'display:none;':''" :status="loadStatus"></u-loadmore>
			</view>
			<u-empty mode="data" marginTop="100" v-if="dataList.length==0" :text="no_text"></u-empty>
		</scroll-view>
	</view>
</template>

<script>
	import listNone from "@/components/listnone/listnone.vue"
	// import app from "@/common/js/comm_url.js";
	export default {
		components: {
			listNone
		},
		data() {
			return {
				comm_img_url: '',
				dataList: [],
				loadStatus: 'loadmore',
				//刷新状态 true 表示下拉刷新已经被触发，false 表示下拉刷新未被触发
				triggered: false,
				page: 1,
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				showFocus:false,
			};
		},
		props: {
			i: {},
			no_text: {},
			is_search: {
				type: Boolean
			}
		},
		onLoad(){
			this.comm_img_url = this.$c.appImg
		},
		methods: {
			setRemarks(e,item){
				let remark=e.detail.value;
				if(item.nickname == remark) return 
				this.$u.api.teamAddRemarks({
					tel:item.tel,
					remarks:remark
				})
				.then(res=>{
					if(res.status){
						uni.showToast({
							icon:'none',
							title:res.msg
						})
						item.descr = remark
						item.isEdit = false
						return
					}
					if(res.code == -5) return 
					uni.showToast({
						icon:'none',
						title:res.msg
					});
				})
				.catch(err=>{console.log(err)})
			},
			changeStatu(item)
			{
				item.isEdit=true
			},
			callTel(para) {
				uni.makePhoneCall({
					phoneNumber: para
				});
			},
			onPullUp() {
				if (this.loadStatus == "loadmore") {
					this.getData();
				}
			},
			onRefresh() {
				if (!this.triggered) {
					this.page = 1;
					this.dataList = [];
					this.getData()
				}
			},
			getData(tel) {
				if (!this.$u.test.isEmpty(tel)) {
					this.page = 1
					this.dataList = []
				}
				//更新刷新状态
				this.triggered = true;
				this.$u.api.teamList({
						page: this.page,
						tel: tel ? tel : ''
					})
					.then(res => {
						if (res.status) {
							if (res.msg.list != null && res.msg.list.length > 0) {
								res.msg.list.forEach(item => item.isEdit = false)
								this.dataList.push(...res.msg.list);
								console.log(this.dataList);
								this.page += 1
								if (res.msg.list.length < 10) {
									this.loadStatus = 'nomore';
								} else {
									this.loadStatus = 'loadmore';
								}
								return
							}
							this.loadStatus = 'nomore';
							return
						}
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					})
					.catch(err => {
						console.log(res);
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}).finally(() => {
						//更新刷新状态
						this.triggered = false;
					})
			},

		}
	}
</script>

<style lang="less">
	// @import url("@/common/css/comm.less");

	.team-item {
		border-bottom: 1px solid #eee;
		padding: 20rpx 0;
		color:#333;
		.item-sign{
			min-width:80rpx;
			text-align: center;
			padding:0 15rpx;
			border-radius: 10rpx;
			background:rgba(208,34,39,0.8);
			color:#fff;
			display: inline-block;
			margin-left:20rpx;
			font-size:28rpx;
			line-height: 45rpx;
		}

		.head {
			position: relative;
		}

		.icon-vip {
			position: absolute;
			bottom: 0;
			right: 0;
			width: 78rpx;
			height: 81rpx;
			margin: 0;
		}

		.icon-item {
			width: 88rpx;
			height: 88rpx;
			margin-right: 20rpx;
			box-shadow: 0 1px 4px #ccc;
			
			border-radius: 50%;
		}

		.item-name {
			
			font-size:30rpx;
			color:#333;
			display: flex;
			align-items: center;

			.pic {
				margin-left: 30rpx;
				width: 28rpx;
				height: 28rpx;
			}

			.name-set {
				word-break: break-all;
			}

			.name-input {
				width: 100rpx;
			}
		}

		.item-time {
			font-size:22rpx;
			color:#999;
		}

		.tel {
			width: 45rpx;
			height: 45rpx;
			margin: 0;
		}

		&:last-child {
			border: 0;
		}
	}
</style>
